// 打印机任务排序
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int func(vector<int>&,int);
int main(){
    int num;
    cin>>num;
    for(int i=0;i<num;++i){
        int n,m;
        cin >> n >> m;
        vector<int> a(n);
        for(int i = 0; i < n; i++)
            cin >> a[i];
        cout<<func(a,m)<<endl;
    }
    return 0;
}
int func(vector<int>& v,int m){
    queue<pair<int,int>> q;
    priority_queue<int> pq;
    for(size_t i=0;i<v.size();++i){
        q.push({i,v[i]});
        pq.push(v[i]);
    }
    int count=0;
    while(!q.empty()){
        int pos = q.front().first;
        int pri = q.front().second;
        q.pop();
        if(pri==pq.top()){
            ++count;
            pq.pop();
            if(pos==m) return count;
        } else
            q.push({pos,pri});
    }
    return count;
}